﻿using MediatR;
using Traceability.Commont.Domains.ScratchTheFat;
using Traceability.Commont.DTOs.CommontFiles;
using Traceability.Commont.Infrastructures.Interfaces;
namespace U.Enterprise.Api.Applications.SalesWeighingEXE
{
    public class SalesWeighingupdateHandler : IRequestHandler<SalesWeighingupdateCommond, Resqults>
    {
        private readonly IBateRepository<SalesWeighing> SalesWeighing;

        public SalesWeighingupdateHandler(IBateRepository<SalesWeighing> SalesWeighing)
        {
            this.SalesWeighing = SalesWeighing;
        }
        public async Task<Resqults> Handle(SalesWeighingupdateCommond request, CancellationToken cancellationToken)
        {
            
            var list=new Resqults() { Code=0};

            var query = SalesWeighing.GetAll().FirstOrDefault(x => x.SalesWeighingID == request.SalesWeighingID);


            if(query!=null)
            {
                query.Tare = request.Tare;
                query.ApproachNo = request.ApproachNo;
                query.Remark = request.Remark;
                query.RepositoryID=request.RepositoryID;
                query.ProductCode=request.ProductCode;
                query.WeightNum=request.WeightNum;
                query.Tare=request.Tare;
                query.NetWeight = request.NetWeight;
                query.AverageWeight=request.AverageWeight;
                query.Remark=request.Remark;
                query.ScaleId=request.ScaleId;
                query.ApproachNo=request.ApproachNo;
                query.ClientID=request.ClientID;
                query.Adjust=request.Adjust;
                query.WeigheTime=query.WeigheTime;
                SalesWeighing.Update(query);


                list.Code = 1;

            }

            return list;


        }
    }
}
